package com.soushangxing.comfyuibackendv2.controller

import com.soushangxing.comfyuibackendv2.bean.GlobalQueue
import com.soushangxing.comfyuibackendv2.bean.ResponseType
import com.soushangxing.comfyuibackendv2.service.ComfyUIModelService
import com.soushangxing.comfyuibackendv2.service.UserService
import jakarta.servlet.http.HttpServletRequest
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.multipart.MultipartFile


@CrossOrigin
@Controller
@ResponseBody
@RequestMapping("workflow")
class WorkflowTestController {

    @Autowired
    lateinit var userService: UserService
    @Autowired
    lateinit var comfyUIModelService: ComfyUIModelService

    /**
     * 国风-图像重绘 - 测试
     */
    @PostMapping("guofeng-v1")
    suspend fun guofengV1(taskId:String, file: MultipartFile, positive: String?, negative: String?, denoise:String?,
                          request: HttpServletRequest
    ): ResponseType {
        val userId = userService.getIdByRequest(request)
        if (userId.isNullOrEmpty()){
            return ResponseType(null,2,"登录已过期")
        }
        return comfyUIModelService.guofengV1(taskId,userId, file,positive, negative, denoise)
    }

    /**
     * 基础文生图 - 测试
     */
    @PostMapping("text2image-basic")
    suspend fun text2imageBasic(taskId:String, positive: String?, negative: String?, denoise:String?,
                                request: HttpServletRequest
    ): ResponseType {
        val userId = userService.getIdByRequest(request)
        if (userId.isNullOrEmpty()){
            return ResponseType(null,2,"登录已过期")
        }
        return comfyUIModelService.basicText2image(taskId,userId, positive,negative,denoise)
    }

}
